package com.aaa.service.Impl;

import com.aaa.entity.Discuss;
import com.aaa.mapper.DiscussMapper;
import com.aaa.service.DiscussService;
import com.aaa.util.DefaultMsg;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评论管理service实现类
 */
@Service
@Transactional
public class DiscussServiceImpl extends ServiceImpl<DiscussMapper, Discuss> implements DiscussService {
    @Resource
    private DiscussMapper discussMapper;

    /**
     * 查询所有评论
     * @param keyword
     * @return
     */
    @Override
    public List<Discuss> listAll(String keyword) {
        return discussMapper.listAll(keyword);
    }

    /**
     * 删除评论
     * @param did
     * @return
     */
    @Override
    public DefaultMsg delete(Integer did) {
        DefaultMsg defaultMsg=new DefaultMsg();
        Integer delete = discussMapper.delete(did);
        if (delete==0){
            defaultMsg.setSuccess(0);
            defaultMsg.setMsg("删除失败");
        }
        return defaultMsg;
    }
}
